<?php
/**
 * @Name: QrCode.php
 * @Author: yashuai 1762910894@qq.com
 */

namespace HugCode\WeChat\Miniprogram;

use HugCode\WeChat\Basics\Toole;
use HugCode\WeChat\Basics\BasicWeChat;
use HugCode\WeChat\Basics\HttpRequest;
use HugCode\WeChat\Basics\Exception\MessageException;

class QrCode extends BasicWeChat
{

    const GET_UNLIMITED = 'wxa/getwxacodeunlimit'; // 适用于需要的码数量极多的业务场景。通过该接口生成的小程序码，永久有效，数量暂无限制

    /**
     * @Desc 获取小程序码
     * @param string $scene
     * @param string $page
     * @param array $params 其他参数
     * @return array|string
     *         转base64格式  'data:image/jpeg;base64,' . base64_encode($result)
     * @throws MessageException
     * @author yashuai 1762910894@qq.com
     */
    public function getUnlimited(string $scene, string $page = '', array $params = [])
    {
        $params['scene'] = $scene;
        $params['page'] = $page;
        $request_url = self::API_BASE_URL_PREFIX . self::GET_UNLIMITED . '?access_token=' . $this->access_token;
        return HttpRequest::instance()->post($request_url, Toole::arr2json($params))->toArray();
    }

}
